package org.codeart.apipassenger.service;

import lombok.extern.slf4j.Slf4j;
import org.codeart.apipassenger.remote.ServiceUserClient;
import org.codeart.common.dto.PassengerUser;
import org.codeart.common.util.R;
import org.codeart.common.dto.TokenResult;
import org.codeart.common.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserService {

    @Autowired
    private ServiceUserClient serviceUserClient;

    public PassengerUser getUserByAccessToken(String accessToken) {
        log.info("accessToken: {}", accessToken);
        // 解析accessToken
        TokenResult tokenResult = JwtUtils.checkToken(accessToken);
        String phone = tokenResult.getPhone();
        log.info("手机号: {}", phone);

        R<PassengerUser> r = serviceUserClient.getUserByPhone(phone);
        return r.getData();
    }

}
